<template>
  <div class="w-full bg-[#171B1C] pb-16 lg:pb-0">
    <CommonHead />
    <NewBanner />
    <SkipHydration>
      <HomeNewHomeSpecial />
      <NewHomeGoods :currentModuleInfo="hotGoodsList?.slice(0, 2)" />
      <NewHomeDiscount />
      <NewHomeGoods
        :lazy-image="true"
        class="mt-4"
        v-if="hotGoodsList?.slice(2, 4).length"
        :currentModuleInfo="hotGoodsList?.slice(2, 4)" />
      <NewHomeDes />
      <HomeGameIntroduce />
      <NewHomeFoot />
      <NewTabsFoot />
    </SkipHydration>
  </div>
</template>

<script setup lang="ts">
import CommonHead from '~/components/basis/CommonHead.vue'
import NewBanner from '~/components/home/NewBanner.vue'
import NewHomeGoods from '~/components/home/NewHomeGoods.vue'
import NewHomeDiscount from '~/components/home/NewHomeDiscount.vue'
import NewHomeDes from '~/components/home/NewHomeDes.vue'
import NewHomeFoot from '~/components/home/NewHomeFoot.vue'
import NewTabsFoot from '~/components/basis/NewTabsFoot.vue'
import { useRequest } from '~/composables/useRequest'
import { useIndexSeo } from '~/composables/useTdk'

definePageMeta({
  layout: 'plain',
})
const { $localePath } = useCommonPlugin()
const i18n = useI18n()
const hotGoodsList = ref([])
const { requestGet } = useRequest()
useIndexSeo()

// 服务端渲染的数据
const { data: homeData } = await useAsyncData<{ data: any[] }>(async () => requestGet('/app/home/recommendDeals'), {
  default: () => ({ data: [] }),
})
if (homeData === null) throw showError({ statusCode: 500, message: 'something went wrong' })
hotGoodsList.value = homeData.value.data
// 百度进入的用户自动跳转至中文
onBeforeMount(() => {
  const isBaidu = document.referrer.includes('baidu')
  if (!isBaidu || i18n.locale.value === 'zh') return
  showLoadingToast({ message: '正在切换中文', duration: 3000 })
  location.replace($localePath('/', 'zh'))
})
</script>

<style lang="scss">
.home-bg {
  background: #171b1c;
}
</style>
